package com.iflytek.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yfliu9
 * @version 1.0
 * @description: TODO
 * @date 2021/9/6 19:35
 */
@RestController
@Slf4j
public class DemoController {

    //熔断之后处理fallBackMethod 快速编写失败方法名
    //这块方法参数以及返回类型需要和被熔断方法保持一致
    @HystrixCommand(defaultFallback = "defaultFallBack")
    @GetMapping("/demo")
    public String demo(Integer id) {
        log.info("demo ok");
        if (id <= 0) {
            throw new RuntimeException("无效id");
        }
        return "demo ok!";
    }

    public String demoFallBack(Integer id) {
        return "当前活动过于火爆，服务已经被熔断";
    }

    public String defaultFallBack() {
        return "网络连接失败，请重试";
    }
}
